home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / sossnt.zip / SOSSNT / SRC / U_XDR.C < prev    next >
C/C++ Source or Header  |  1993-02-28  |  18KB  |  786 lines

  1. /* @(#)unfs_xdr.c    1.2 86/06/30 UNFSSRC */
  2.  
  3. /*
  4.  * Copyright (c) 1986 Sun Microsystems, Inc.
  5.  */
  6.  
  7. #include "common.h"
  8.  
  9. #ifdef UNFSDEBUG
  10. extern int unfsdebug;
  11.  
  12. char *xdropnames[] = {"encode", "decode", "free"};
  13. #endif
  14.  
  15. /*
  16.  * These are the XDR routines used to serialize and deserialize
  17.  * the various structures passed as parameters accross the network
  18.  * between NFS clients and servers.
  19.  */
  20.  
  21.  
  22. /*
  23.  * Arguments to remote write and writecache
  24.  */
  25. bool_t
  26. xdr_writeargs(xdrs, wa)
  27.     XDR *xdrs;
  28.     struct nfswriteargs *wa;
  29. {
  30.     if (xdr_fhandle(xdrs, &wa->wa_fhandle) &&
  31.         xdr_long(xdrs, (long *)&wa->wa_begoff) &&
  32.         xdr_long(xdrs, (long *)&wa->wa_offset) &&
  33.         xdr_long(xdrs, (long *)&wa->wa_totcount) &&
  34.         xdr_bytes(xdrs, &wa->wa_data, (u_int *)&wa->wa_count,
  35.           NFS_MAXDATA) ) {
  36. #ifdef UNFSDEBUG
  37.         dprint(unfsdebug, 6, "xdr_writeargs: %s off %d ct %d\n",
  38.             xdropnames[(int)xdrs->x_op],
  39.             wa->wa_offset, wa->wa_totcount);
  40. #endif
  41.         return (TRUE);
  42.     }
  43. #ifdef UNFSDEBUG
  44.     dprint(unfsdebug, 2, "xdr_writeargs: %s FAILED\n",
  45.         xdropnames[(int)xdrs->x_op]);
  46. #endif
  47.     return (FALSE);
  48. }
  49.  
  50.  
  51. /*
  52.  * File attributes
  53.  */
  54. bool_t
  55. xdr_fattr(xdrs, na)
  56.     XDR *xdrs;
  57.     struct nfsfattr *na;
  58. {
  59.     long FAR *ptr;
  60.  
  61. #ifdef UNFSDEBUG
  62.     dprint(unfsdebug, 6, "xdr_fattr: %s\n",
  63.         xdropnames[(int)xdrs->x_op]);
  64. #endif
  65.     if (xdrs->x_op == XDR_ENCODE) {
  66.         ptr = XDR_INLINE(xdrs, 17 * BYTES_PER_XDR_UNIT);
  67.         if (ptr != NULL) {
  68.             IXDR_PUT_ENUM(ptr, na->na_type);
  69.             IXDR_PUT_LONG(ptr, na->na_mode);
  70.             IXDR_PUT_LONG(ptr, na->na_nlink);
  71.             IXDR_PUT_LONG(ptr, na->na_uid);
  72.             IXDR_PUT_LONG(ptr, na->na_gid);
  73.             IXDR_PUT_LONG(ptr, na->na_size);
  74.             IXDR_PUT_LONG(ptr, na->na_blocksize);
  75.             IXDR_PUT_LONG(ptr, na->na_rdev);
  76.             IXDR_PUT_LONG(ptr, na->na_blocks);
  77.             IXDR_PUT_LONG(ptr, na->na_fsid);
  78.             IXDR_PUT_LONG(ptr, na->na_nodeid);
  79.             IXDR_PUT_LONG(ptr, na->na_atime.tv_sec);
  80.             IXDR_PUT_LONG(ptr, na->na_atime.tv_usec);
  81.             IXDR_PUT_LONG(ptr, na->na_mtime.tv_sec);
  82.             IXDR_PUT_LONG(ptr, na->na_mtime.tv_usec);
  83.             IXDR_PUT_LONG(ptr, na->na_ctime.tv_sec);
  84.             IXDR_PUT_LONG(ptr, na->na_ctime.tv_usec);
  85.             return (TRUE);
  86.         }
  87.     } else {
  88.         ptr = XDR_INLINE(xdrs, 17 * BYTES_PER_XDR_UNIT);
  89.         if (ptr != NULL) {
  90.             na->na_type = IXDR_GET_ENUM(ptr, enum nfsftype);
  91.             na->na_mode = IXDR_GET_LONG(ptr);
  92.             na->na_nlink = IXDR_GET_LONG(ptr);
  93.             na->na_uid = IXDR_GET_LONG(ptr);
  94.             na->na_gid = IXDR_GET_LONG(ptr);
  95.             na->na_size = IXDR_GET_LONG(ptr);
  96.             na->na_blocksize = IXDR_GET_LONG(ptr);
  97.             na->na_rdev = IXDR_GET_LONG(ptr);
  98.             na->na_blocks = IXDR_GET_LONG(ptr);
  99.             na->na_fsid = IXDR_GET_LONG(ptr);
  100.             na->na_nodeid = IXDR_GET_LONG(ptr);
  101.             na->na_atime.tv_sec = IXDR_GET_LONG(ptr);
  102.             na->na_atime.tv_usec = IXDR_GET_LONG(ptr);
  103.             na->na_mtime.tv_sec = IXDR_GET_LONG(ptr);
  104.             na->na_mtime.tv_usec = IXDR_GET_LONG(ptr);
  105.             na->na_ctime.tv_sec = IXDR_GET_LONG(ptr);
  106.             na->na_ctime.tv_usec = IXDR_GET_LONG(ptr);
  107.             return (TRUE);
  108.         }
  109.     }
  110.     if (xdr_enum(xdrs, (enum_t *)&na->na_type) &&
  111.         xdr_u_long(xdrs, &na->na_mode) &&
  112.         xdr_u_long(xdrs, &na->na_nlink) &&
  113.         xdr_u_long(xdrs, &na->na_uid) &&
  114.         xdr_u_long(xdrs, &na->na_gid) &&
  115.         xdr_u_long(xdrs, &na->na_size) &&
  116.         xdr_u_long(xdrs, &na->na_blocksize) &&
  117.         xdr_u_long(xdrs, &na->na_rdev) &&
  118.         xdr_u_long(xdrs, &na->na_blocks) &&
  119.         xdr_u_long(xdrs, &na->na_fsid) &&
  120.         xdr_u_long(xdrs, &na->na_nodeid) &&
  121.         xdr_timeval(xdrs, &na->na_atime) &&
  122.         xdr_timeval(xdrs, &na->na_mtime) &&
  123.         xdr_timeval(xdrs, &na->na_ctime) ) {
  124.         return (TRUE);
  125.     }
  126. #ifdef UNFSDEBUG
  127.     dprint(unfsdebug, 2, "xdr_fattr: %s FAILED\n",
  128.         xdropnames[(int)xdrs->x_op]);
  129. #endif
  130.     return (FALSE);
  131. }
  132.  
  133. /*
  134.  * Arguments to remote read
  135.  */
  136. bool_t
  137. xdr_readargs(xdrs, ra)
  138.     XDR *xdrs;
  139.     struct nfsreadargs *ra;
  140. {
  141.  
  142.     if (xdr_fhandle(xdrs, &ra->ra_fhandle) &&
  143.         xdr_long(xdrs, (long *)&ra->ra_offset) &&
  144.         xdr_long(xdrs, (long *)&ra->ra_count) &&
  145.         xdr_long(xdrs, (long *)&ra->ra_totcount) ) {
  146. #ifdef UNFSDEBUG
  147.         dprint(unfsdebug, 6, "xdr_readargs: %s off %d ct %d\n",
  148.             xdropnames[(int)xdrs->x_op],
  149.             ra->ra_offset, ra->ra_totcount);
  150. #endif
  151.         return (TRUE);
  152.     }
  153. #ifdef UNFSDEBUG
  154.     dprint(unfsdebug, 2, "xdr_raedargs: %s FAILED\n",
  155.         xdropnames[(int)xdrs->x_op]);
  156. #endif
  157.     return (FALSE);
  158. }
  159.  
  160.  
  161. /*
  162.  * Status OK portion of remote read reply
  163.  */
  164. bool_t
  165. xdr_rrok(xdrs, rrok)
  166.     XDR *xdrs;
  167.     struct nfsrrok *rrok;
  168. {
  169.  
  170.     if (xdr_fattr(xdrs, &rrok->rrok_attr)) {
  171.         if (xdrs->x_op == XDR_ENCODE && rrok->rrok_bp) {
  172.         } else {            /* client side */
  173.             if (xdr_bytes(xdrs, &rrok->rrok_data,
  174.                 (u_int *)&rrok->rrok_count, NFS_MAXDATA) ) {
  175. #ifdef UNFSDEBUG
  176.                 dprint(unfsdebug, 6, "xdr_rrok: %s %d addr %x\n",
  177.                     xdropnames[(int)xdrs->x_op],
  178.                     rrok->rrok_count, rrok->rrok_data);
  179. #endif
  180.                 return (TRUE);
  181.             }
  182.         }
  183.     }
  184. #ifdef UNFSDEBUG
  185.     dprint(unfsdebug, 2, "xdr_rrok: %s FAILED\n",
  186.         xdropnames[(int)xdrs->x_op]);
  187. #endif
  188.     return (FALSE);
  189. }
  190.  
  191. struct xdr_discrim rdres_discrim[2] = {
  192.     { (int)NFS_OK, xdr_rrok },
  193.     { __dontcare__, NULL_xdrproc_t }
  194. };
  195.  
  196. /*
  197.  * Reply from remote read
  198.  */
  199. bool_t
  200. xdr_rdresult(xdrs, rr)
  201.     XDR *xdrs;
  202.     struct nfsrdresult *rr;
  203. {
  204.  
  205. #ifdef UNFSDEBUG
  206.     dprint(unfsdebug, 6, "xdr_rdresult: %s\n", xdropnames[(int)xdrs->x_op]);
  207. #endif
  208.     if (xdr_union(xdrs, (enum_t *)&(rr->rr_status),
  209.           (caddr_t)&(rr->rr_ok), rdres_discrim, xdr_void) ) {
  210.         return (TRUE);
  211.     }
  212.  
  213. #ifdef UNFSDEBUG
  214.     dprint(unfsdebug, 2, "xdr_rdresult: %s FAILED\n",
  215.         xdropnames[(int)xdrs->x_op]);
  216. #endif
  217.     return (FALSE);
  218. }
  219.  
  220. /*
  221.  * File attributes which can be set
  222.  */
  223. bool_t
  224. xdr_sattr(xdrs, sa)
  225.     XDR *xdrs;
  226.     struct nfssattr *sa;
  227. {
  228.  
  229.     if (xdr_u_long(xdrs, &sa->sa_mode) &&
  230.         xdr_u_long(xdrs, &sa->sa_uid) &&
  231.         xdr_u_long(xdrs, &sa->sa_gid) &&
  232.         xdr_u_long(xdrs, &sa->sa_size) &&
  233.         xdr_timeval(xdrs, &sa->sa_atime) &&
  234.         xdr_timeval(xdrs, &sa->sa_mtime) ) {
  235. #ifdef UNFSDEBUG
  236.         dprint(unfsdebug, 6,
  237.             "xdr_sattr: %s mode %o uid %d gid %d size %d\n",
  238.             xdropnames[(int)xdrs->x_op], sa->sa_mode, sa->sa_uid,
  239.             sa->sa_gid, sa->sa_size);
  240. #endif
  241.         return (TRUE);
  242.     }
  243. #ifdef UNFSDEBUG
  244.     dprint(unfsdebug, 2, "xdr_sattr: %s FAILED\n",
  245.         xdropnames[(int)xdrs->x_op]);
  246. #endif
  247.     return (FALSE);
  248. }
  249.  
  250. struct xdr_discrim attrstat_discrim[2] = {
  251.     { (int)NFS_OK, xdr_fattr },
  252.     { __dontcare__, NULL_xdrproc_t }
  253. };
  254.  
  255. /*
  256.  * Reply status with file attributes
  257.  */
  258. bool_t
  259. xdr_attrstat(xdrs, ns)
  260.     XDR *xdrs;
  261.     struct nfsattrstat *ns;
  262. {
  263.  
  264.     if (xdr_union(xdrs, (enum_t *)&(ns->ns_status),
  265.           (caddr_t)&(ns->ns_attr), attrstat_discrim, xdr_void) ) {
  266. #ifdef UNFSDEBUG
  267.         dprint(unfsdebug, 6, "xdr_attrstat: %s stat %d\n",
  268.             xdropnames[(int)xdrs->x_op], ns->ns_status);
  269. #endif
  270.         return (TRUE);
  271.     }
  272. #ifdef UNFSDEBUG
  273.     dprint(unfsdebug, 2, "xdr_attrstat: %s FAILED\n",
  274.         xdropnames[(int)xdrs->x_op]);
  275. #endif
  276.     return (FALSE);
  277. }
  278.  
  279. /*
  280.  * NFS_OK part of read sym link reply union
  281.  */
  282. bool_t
  283. xdr_srok(xdrs, srok)
  284.     XDR *xdrs;
  285.     struct nfssrok *srok;
  286. {
  287.  
  288.     if (xdr_bytes(xdrs, &srok->srok_data, (u_int *)&srok->srok_count,
  289.         NFS_MAXPATHLEN) ) {
  290.         return (TRUE);
  291.     }
  292. #ifdef UNFSDEBUG
  293.     dprint(unfsdebug, 2, "xdr_srok: %s FAILED\n",
  294.         xdropnames[(int)xdrs->x_op]);
  295. #endif
  296.     return (FALSE);
  297. }
  298.  
  299. struct xdr_discrim rdlnres_discrim[2] = {
  300.     { (int)NFS_OK, xdr_srok },
  301.     { __dontcare__, NULL_xdrproc_t }
  302. };
  303.  
  304. /*
  305.  * Result of reading symbolic link
  306.  */
  307. bool_t
  308. xdr_rdlnres(xdrs, rl)
  309.     XDR *xdrs;
  310.     struct nfsrdlnres *rl;
  311. {
  312.  
  313. #ifdef UNFSDEBUG
  314.     dprint(unfsdebug, 6, "xdr_rdlnres: %s\n", xdropnames[(int)xdrs->x_op]);
  315. #endif
  316.     if (xdr_union(xdrs, (enum_t *)&(rl->rl_status),
  317.           (caddr_t)&(rl->rl_srok), rdlnres_discrim, xdr_void) ) {
  318.         return (TRUE);
  319.     }
  320. #ifdef UNFSDEBUG
  321.     dprint(unfsdebug, 2, "xdr_rdlnres: %s FAILED\n",
  322.         xdropnames[(int)xdrs->x_op]);
  323. #endif
  324.     return (FALSE);
  325. }
  326.  
  327. /*
  328.  * Arguments to readdir
  329.  */
  330. bool_t
  331. xdr_rddirargs(xdrs, rda)
  332.     XDR *xdrs;
  333.     struct nfsrddirargs *rda;
  334. {
  335.  
  336.     if (xdr_fhandle(xdrs, &rda->rda_fh) &&
  337.         xdr_u_long(xdrs, &rda->rda_offset) &&
  338.         xdr_u_long(xdrs, &rda->rda_count) ) {
  339. #ifdef UNFSDEBUG
  340.         dprint(unfsdebug, 6,
  341.             "xdr_rddirargs: %s fh %d, off %d, cnt %d\n",
  342.             xdropnames[(int)xdrs->x_op],
  343.             rda->rda_fh.fh_pn, rda->rda_offset,
  344.             rda->rda_count);
  345. #endif
  346.         return (TRUE);
  347.     }
  348. #ifdef UNFSDEBUG
  349.     dprint(unfsdebug, 2, "xdr_rddirargs: %s FAILED\n",
  350.         xdropnames[(int)xdrs->x_op]);
  351. #endif
  352.     return (FALSE);
  353. }
  354.  
  355. /*
  356.  * Directory read reply:
  357.  * union (enum status) {
  358.  *    NFS_OK: entlist;
  359.  *        boolean eof;
  360.  *    default:
  361.  * }
  362.  *
  363.  * Directory entries
  364.  *    struct  direct {
  365.  *        u_long  d_fileno;           * inode number of entry *
  366.  *        u_short d_reclen;           * length of this record *
  367.  *        u_short d_namlen;           * length of string in d_name *
  368.  *        char    d_name[MAXNAMLEN + 1];  * name no longer than this *
  369.  *    };
  370.  * are on the wire as:
  371.  * union entlist (boolean valid) {
  372.  *     TRUE: struct dirent;
  373.  *          u_long nxtoffset;
  374.  *           union entlist;
  375.  *    FALSE:
  376.  * }
  377.  * where dirent is:
  378.  *     struct dirent {
  379.  *        u_long    de_fid;
  380.  *        string    de_name<NFS_MAXNAMELEN>;
  381.  *    }
  382.  */
  383.  
  384. #define    nextdp(udp)    ((struct udirect *)((u_long)(udp) + (udp)->d_reclen))
  385. #undef DIRSIZ
  386. #define DIRSIZ(udp)    \
  387.     (sizeof(struct udirect) - (MAXNAMLEN+1)+ (udp)->d_namlen)
  388.  
  389. /*
  390.  * ENCODE ONLY
  391.  */
  392. bool_t
  393. xdr_putrddirres(xdrs, rd)
  394.     XDR *xdrs;
  395.     struct nfsrddirres *rd;
  396. {
  397.     struct udirect *udp;
  398.     char *name;
  399.     int size;
  400.     int xdrpos;
  401.     u_int namlen;
  402.     u_long offset;
  403.     bool_t true = TRUE;
  404.     bool_t false = FALSE;
  405.  
  406. #ifdef UNFSDEBUG
  407.     dprint(unfsdebug, 6, "xdr_putrddirres: %s size %d offset %d\n",
  408.         xdropnames[(int)xdrs->x_op], rd->rd_size, rd->rd_offset);
  409. #endif
  410.     if (xdrs->x_op != XDR_ENCODE) {
  411.         return (FALSE);
  412.     }
  413.     if (!xdr_enum(xdrs, (enum_t *)&rd->rd_status)) {
  414.         return (FALSE);
  415.     }
  416.     if (rd->rd_status != NFS_OK) {
  417.         return (TRUE);
  418.     }
  419.  
  420.     xdrpos = XDR_GETPOS(xdrs);
  421.     for (offset = rd->rd_offset, size = rd->rd_size, udp = rd->rd_entries;
  422.          size > 0;
  423.          size -= udp->d_reclen, udp = nextdp(udp)) {
  424.         if (udp->d_reclen == 0 || DIRSIZ(udp) > udp->d_reclen) {
  425. #ifdef UNFSDEBUG
  426.             dprint(unfsdebug, 10,
  427.                   "xdr_putrddirres: entry %d %s(%d) %d %d %d\n",
  428.                   udp->d_fileno,udp->d_name,udp->d_namlen,udp->d_offset,
  429.                   udp->d_reclen, DIRSIZ(udp));
  430.             dprint(unfsdebug, 2, "xdr_putrddirres: bad directory\n");
  431. #endif
  432.             return (FALSE);
  433.         }
  434.         offset = udp->d_offset;
  435. #ifdef UNFSDEBUG
  436.         dprint(unfsdebug, 10,
  437.             "xdr_putrddirres: entry %d %s(%d) %d %d %d %d\n",
  438.             udp->d_fileno, udp->d_name, udp->d_namlen, offset,
  439.             udp->d_reclen, XDR_GETPOS(xdrs), size);
  440. #endif
  441.         if (udp->d_fileno == 0) {
  442.             continue;
  443.         }
  444.         name = udp->d_name;
  445.         namlen = udp->d_namlen;
  446.         if (!xdr_bool(xdrs, &true) ||
  447.             !xdr_u_long(xdrs, &udp->d_fileno) ||
  448.             !xdr_bytes(xdrs, &name, &namlen, NFS_MAXNAMLEN) ||
  449.             !xdr_u_long(xdrs, &offset) ) {
  450.             return (FALSE);
  451.         }
  452.         if (XDR_GETPOS(xdrs) - xdrpos >= rd->rd_bufsize) {
  453.             rd->rd_eof = FALSE;
  454.             break;
  455.         }
  456.     }
  457.     if (!xdr_bool(xdrs, &false)) {
  458.         return (FALSE);
  459.     }
  460.     if (!xdr_bool(xdrs, &rd->rd_eof)) {
  461.         return (FALSE);
  462.     }
  463.     return (TRUE);
  464. }
  465.  
  466. #define    roundtoint(x)    (((x) + sizeof(int)) & ~(sizeof(int) - 1))
  467. #define    reclen(udp)    roundtoint(((udp)->d_namlen + 1 + sizeof(u_long) +\
  468.                 2 * sizeof(u_short)))
  469.  
  470. /*
  471.  * DECODE ONLY
  472.  */
  473. bool_t
  474. xdr_getrddirres(xdrs, rd)
  475.     XDR *xdrs;
  476.     struct nfsrddirres *rd;
  477. {
  478.     struct udirect *udp;
  479.     int size;
  480.     bool_t valid;
  481.     u_long offset = (u_long)-1;
  482.  
  483.     if (!xdr_enum(xdrs, (enum_t *)&rd->rd_status)) {
  484.         return (FALSE);
  485.     }
  486.     if (rd->rd_status != NFS_OK) {
  487.         return (TRUE);
  488.     }
  489.  
  490. #ifdef UNFSDEBUG
  491.     dprint(unfsdebug, 6, "xdr_getrddirres: %s size %d\n",
  492.         xdropnames[(int)xdrs->x_op], rd->rd_size);
  493. #endif
  494.     size = rd->rd_size;
  495.     udp = rd->rd_entries;
  496.     for (;;) {
  497.         if (!xdr_bool(xdrs, &valid)) {
  498.             return (FALSE);
  499.         }
  500.         if (valid) {
  501.             if (!xdr_u_long(xdrs, &udp->d_fileno) ||
  502.                 !xdr_u_short(xdrs, &udp->d_namlen) ||
  503.                 (reclen(udp) > (unsigned)size) ||
  504.                 !xdr_opaque(xdrs, udp->d_name, (u_int)udp->d_namlen)||
  505.                 !xdr_u_long(xdrs, &offset) ) {
  506. #ifdef UNFSDEBUG
  507.                 dprint(unfsdebug, 2,
  508.                     "xdr_getrddirres: entry error\n");
  509. #endif
  510.                 return (FALSE);
  511.             }
  512.             udp->d_reclen = reclen(udp);
  513.             udp->d_name[udp->d_namlen] = '\0';
  514. #ifdef UNFSDEBUG
  515.             dprint(unfsdebug, 10,
  516.                 "xdr_getrddirres: entry %d %s(%d) %d %d\n",
  517.                 udp->d_fileno, udp->d_name, udp->d_namlen,
  518.                 udp->d_reclen, offset);
  519. #endif
  520.         } else {
  521.             break;
  522.         }
  523.         size -= udp->d_reclen;
  524.         if (size <= 0) {
  525.             return (FALSE);
  526.         }
  527.         udp = nextdp(udp);
  528.     }
  529.     if (!xdr_bool(xdrs, &rd->rd_eof)) {
  530.         return (FALSE);
  531.     }
  532.     rd->rd_size = (int)udp - (int)(rd->rd_entries);
  533.     rd->rd_offset = offset;
  534. #ifdef UNFSDEBUG
  535.     dprint(unfsdebug, 6,
  536.         "xdr_getrddirres: returning size %d offset %d eof %d\n",
  537.         rd->rd_size, rd->rd_offset, rd->rd_eof);
  538. #endif
  539.     return (TRUE);
  540. }
  541.  
  542. /*
  543.  * Arguments for directory operations
  544.  */
  545. bool_t
  546. xdr_diropargs(xdrs, da)
  547.     XDR *xdrs;
  548.     struct nfsdiropargs *da;
  549. {
  550.  
  551.     if (xdr_fhandle(xdrs, &da->da_fhandle) &&
  552.         xdr_string(xdrs, &da->da_name, NFS_MAXNAMLEN) ) {
  553. #ifdef UNFSDEBUG
  554.         dprint(unfsdebug, 6, "xdr_diropargs: %s %s '%s'\n",
  555.             xdropnames[(int)xdrs->x_op], da->da_fhandle.fh_pn,
  556.             da->da_name);
  557. #endif
  558.         return (TRUE);
  559.     }
  560. #ifdef UNFSDEBUG
  561.     dprint(unfsdebug, 2, "xdr_diropargs: FAILED\n");
  562. #endif
  563.     return (FALSE);
  564. }
  565.  
  566. /*
  567.  * NFS_OK part of directory operation result
  568.  */
  569. bool_t
  570. xdr_drok(xdrs, drok)
  571.     XDR *xdrs;
  572.     struct nfsdrok *drok;
  573. {
  574.  
  575.     if (xdr_fhandle(xdrs, &drok->drok_fhandle) &&
  576.         xdr_fattr(xdrs, &drok->drok_attr) ) {
  577.         return (TRUE);
  578.     }
  579. #ifdef UNFSDEBUG
  580.     dprint(unfsdebug, 2, "xdr_drok: FAILED\n");
  581. #endif
  582.     return (FALSE);
  583. }
  584.  
  585. struct xdr_discrim diropres_discrim[2] = {
  586.     { (int)NFS_OK, xdr_drok },
  587.     { __dontcare__, NULL_xdrproc_t }
  588. };
  589.  
  590. /*
  591.  * Results from directory operation 
  592.  */
  593. bool_t
  594. xdr_diropres(xdrs, dr)
  595.     XDR *xdrs;
  596.     struct nfsdiropres *dr;
  597. {
  598.  
  599.     if (xdr_union(xdrs, (enum_t *)&(dr->dr_status),
  600.           (caddr_t)&(dr->dr_drok), diropres_discrim, xdr_void) ) {
  601. #ifdef UNFSDEBUG
  602.         dprint(unfsdebug, 6, "xdr_diropres: %s stat %d\n",
  603.             xdropnames[(int)xdrs->x_op], dr->dr_status);
  604. #endif
  605.         return (TRUE);
  606.     }
  607. #ifdef UNFSDEBUG
  608.     dprint(unfsdebug, 2, "xdr_diropres: FAILED\n");
  609. #endif
  610.     return (FALSE);
  611. }
  612.  
  613. /*
  614.  * Time structure
  615.  */
  616. bool_t
  617. xdr_timeval(xdrs, tv)
  618.     XDR *xdrs;
  619.     struct timeval *tv;
  620. {
  621.  
  622.     if (xdr_long(xdrs, &tv->tv_sec) &&
  623.         xdr_long(xdrs, &tv->tv_usec) ) {
  624.         return (TRUE);
  625.     }
  626. #ifdef UNFSDEBUG
  627.     dprint(unfsdebug, 2, "xdr_timeval: FAILED\n");
  628. #endif
  629.     return (FALSE);
  630. }
  631.  
  632. /*
  633.  * arguments to setattr
  634.  */
  635. bool_t
  636. xdr_saargs(xdrs, argp)
  637.     XDR *xdrs;
  638.     struct nfssaargs *argp;
  639. {
  640.  
  641.     if (xdr_fhandle(xdrs, &argp->saa_fh) &&
  642.         xdr_sattr(xdrs, &argp->saa_sa) ) {
  643. #ifdef UNFSDEBUG
  644.         dprint(unfsdebug, 6, "xdr_saargs: %s %s\n",
  645.             xdropnames[(int)xdrs->x_op], argp->saa_fh.fh_pn);
  646. #endif
  647.         return (TRUE);
  648.     }
  649. #ifdef UNFSDEBUG
  650.     dprint(unfsdebug, 2, "xdr_saargs: FAILED\n");
  651. #endif
  652.     return (FALSE);
  653. }
  654.  
  655. /*
  656.  * arguments to create and mkdir
  657.  */
  658. bool_t
  659. xdr_creatargs(xdrs, argp)
  660.     XDR *xdrs;
  661.     struct nfscreatargs *argp;
  662. {
  663.  
  664.     if (xdr_diropargs(xdrs, &argp->ca_da) &&
  665.         xdr_sattr(xdrs, &argp->ca_sa) ) {
  666.         return (TRUE);
  667.     }
  668. #ifdef UNFSDEBUG
  669.     dprint(unfsdebug, 2, "xdr_creatargs: FAILED\n");
  670. #endif
  671.     return (FALSE);
  672. }
  673.  
  674. /*
  675.  * arguments to link
  676.  */
  677. bool_t
  678. xdr_linkargs(xdrs, argp)
  679.     XDR *xdrs;
  680.     struct nfslinkargs *argp;
  681. {
  682.  
  683.     if (xdr_fhandle(xdrs, &argp->la_from) &&
  684.         xdr_diropargs(xdrs, &argp->la_to) ) {
  685.         return (TRUE);
  686.     }
  687. #ifdef UNFSDEBUG
  688.     dprint(unfsdebug, 2, "xdr_linkargs: FAILED\n");
  689. #endif
  690.     return (FALSE);
  691. }
  692.  
  693. /*
  694.  * arguments to rename
  695.  */
  696. bool_t
  697. xdr_rnmargs(xdrs, argp)
  698.     XDR *xdrs;
  699.     struct nfsrnmargs *argp;
  700. {
  701.  
  702.     if (xdr_diropargs(xdrs, &argp->rna_from) &&
  703.         xdr_diropargs(xdrs, &argp->rna_to) ) {
  704.         return (TRUE);
  705.     }
  706. #ifdef UNFSDEBUG
  707.     dprint(unfsdebug, 2, "xdr_rnmargs: FAILED\n");
  708. #endif
  709.     return (FALSE);
  710. }
  711.  
  712. /*
  713.  * arguments to symlink
  714.  */
  715. bool_t
  716. xdr_slargs(xdrs, argp)
  717.     XDR *xdrs;
  718.     struct nfsslargs *argp;
  719. {
  720.  
  721.     if (xdr_diropargs(xdrs, &argp->sla_from) &&
  722.         xdr_string(xdrs, &argp->sla_tnm, (u_int)NFS_MAXPATHLEN) &&
  723.         xdr_sattr(xdrs, &argp->sla_sa) ) {
  724.         return (TRUE);
  725.     }
  726. #ifdef UNFSDEBUG
  727.     dprint(unfsdebug, 2, "xdr_slargs: FAILED\n");
  728. #endif
  729.     return (FALSE);
  730. }
  731.  
  732. /*
  733.  * NFS_OK part of statfs operation
  734.  */
  735. xdr_fsok(xdrs, fsok)
  736.     XDR *xdrs;
  737.     struct nfsstatfsok *fsok;
  738. {
  739.  
  740.     if (xdr_long(xdrs, (long *)&fsok->fsok_tsize) &&
  741.         xdr_long(xdrs, (long *)&fsok->fsok_bsize) &&
  742.         xdr_long(xdrs, (long *)&fsok->fsok_blocks) &&
  743.         xdr_long(xdrs, (long *)&fsok->fsok_bfree) &&
  744.         xdr_long(xdrs, (long *)&fsok->fsok_bavail) ) {
  745. #ifdef UNFSDEBUG
  746.         dprint(unfsdebug, 6,
  747.             "xdr_fsok: %s tsz %d bsz %d blks %d bfree %d bavail %d\n",
  748.             xdropnames[(int)xdrs->x_op], fsok->fsok_tsize,
  749.             fsok->fsok_bsize, fsok->fsok_blocks, fsok->fsok_bfree,
  750.             fsok->fsok_bavail);
  751. #endif
  752.         return (TRUE);
  753.     }
  754. #ifdef UNFSDEBUG
  755.     dprint(unfsdebug, 2, "xdr_fsok: FAILED\n");
  756. #endif
  757.     return (FALSE);
  758. }
  759.  
  760. struct xdr_discrim statfs_discrim[2] = {
  761.     { (int)NFS_OK, xdr_fsok },
  762.     { __dontcare__, NULL_xdrproc_t }
  763. };
  764.  
  765. /*
  766.  * Results of statfs operation
  767.  */
  768. xdr_statfs(xdrs, fs)
  769.     XDR *xdrs;
  770.     struct nfsstatfs *fs;
  771. {
  772.  
  773.     if (xdr_union(xdrs, (enum_t *)&(fs->fs_status),
  774.           (caddr_t)&(fs->fs_fsok), statfs_discrim, xdr_void) ) {
  775. #ifdef UNFSDEBUG
  776.         dprint(unfsdebug, 6, "xdr_statfs: %s stat %d\n",
  777.             xdropnames[(int)xdrs->x_op], fs->fs_status);
  778. #endif
  779.         return (TRUE);
  780.     }
  781. #ifdef UNFSDEBUG
  782.     dprint(unfsdebug, 2, "xdr_statfs: FAILED\n");
  783. #endif
  784.     return (FALSE);
  785. }
  786.